package com.ruoyi.project.module.version.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.module.version.domain.Version;
import com.ruoyi.project.module.version.service.IVersionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * app更新 信息操作处理
 * 
 * @author frey
 * @date 2018-10-10
 */
@Controller
@RequestMapping("/module/version")
public class VersionController extends BaseController
{
    private String prefix = "module/version";
	
	@Autowired
	private IVersionService versionService;
	
	@RequiresPermissions("module:version:view")
	@GetMapping()
	public String version()
	{
	    return prefix + "/version";
	}
	
	/**
	 * 查询app更新列表
	 */
	@RequiresPermissions("module:version:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Version version)
	{
		startPage();
        List<Version> list = versionService.selectVersionList(version);
		return getDataTable(list);
	}
	
	/**
	 * 新增app更新
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存app更新
	 */
	@RequiresPermissions("module:version:add")
	@Log(title = "app更新", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Version version)
	{		
		return toAjax(versionService.insertVersion(version));
	}

	/**
	 * 修改app更新
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Version version = versionService.selectVersionById(id);
		mmap.put("version", version);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存app更新
	 */
	@RequiresPermissions("module:version:edit")
	@Log(title = "app更新", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Version version)
	{		
		return toAjax(versionService.updateVersion(version));
	}
	
	/**
	 * 删除app更新
	 */
	@RequiresPermissions("module:version:remove")
	@Log(title = "app更新", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(versionService.deleteVersionByIds(ids));
	}
	
}
